<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: relative;
            width: 370px;
            margin: 100px auto;
            border-bottom: 1px solid #ccc;
        }

        input {
            width: 370px;
            height: 35px;
            outline: none;
            border: none;
        }

        .box img {
            position: absolute;
            top: 2px;
            right: 2px;
            width: 30px;
        }
    </style>
</head>

<body>
    <div class="box">
        <label for="">
            <img src="image/02.webp" alt="" id="but">
        </label>
        <input type="password" id="ipt">
    </div>
    <script>
        // 需求 显示和隐藏密码
        // 1.确定事件源 元素
        var but = document.getElementById('but')
        var ipt = document.getElementById('ipt')
        //  2.绑定事件 执行程序
        var flag = 0
        but.onclick = function () {
            if (flag == 0) {
                ipt.type = 'text'
                but.src = 'image/01.webp'
                flag = 1
            } else {
                ipt.type = 'password'
                but.src = 'image/02.webp'
                flag = 0
            }
        }
    </script>
</body>

</html>